﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using Finder.Views;

namespace Finder
{
    public class FinderGuiHelper
    {
        /// <summary>
        /// Others the instances running.
        /// </summary>
        /// <param name="processName">
        /// The process Name.
        /// </param>
        public static void PreventMultipleInstances(string processName)
        {
            if (Process.GetProcesses().Where(x => x.ProcessName == processName).Count() > 1)
            {
                Process.GetCurrentProcess().Close();
            }
        }

        /// <summary>
        /// Determines the visibility of email sending button, based on wether specified user has email or not.
        /// </summary>
        /// <param name="employeeEmail">
        /// The employee Email.
        /// </param>
        /// <returns>
        /// Visibility based on email adress being set or not.
        /// </returns>
        internal static Visibility EmailIconVisibility(string employeeEmail)
        {
            return !string.IsNullOrEmpty(employeeEmail)
                       ? Visibility.Visible
                       : Visibility.Hidden;
        }

        /// <summary>
        /// Shows the finder.
        /// </summary>
        /// <param name="mainWindow">
        /// The main Window.
        /// </param>
        internal static void ShowFinder(MainWindow mainWindow)
        {
            mainWindow.Show();
            mainWindow.WindowState = WindowState.Normal;
            mainWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            mainWindow.BringIntoView();
            mainWindow.Topmost = true;
        }

        /// <summary>
        /// Hides the finder.
        /// </summary>
        /// <param name="mainWindow">
        /// The main Window.
        /// </param>
        internal static void HideFinder(MainWindow mainWindow)
        {
            mainWindow.Hide();
            mainWindow.WindowState = WindowState.Minimized;
        }
    }
}
